<?php

// 会员红包记录表

namespace app\console\model;

use think\Model;
use think\Request;

class MemberPacket extends Model
{

    // 会员表 会员红包记录关联
    public function Member()
    {
        return $this->belongsTo('Member','member_id','id')->field('id,username,name');
    }

    // 模型事件
    protected static function init()
    {

        // 写入前
        self::event('before_write', function ($data) {
            $interval_timer = explode(' / ', Request::instance()->param('interval_timer'));
            $data->start_time = strtotime($interval_timer[0]);
            $data->end_time = strtotime($interval_timer[1]);
        });

        // 新增后
        // self::event('after_insert', function ($data) {
        //     $model = new MemberMessageModel();
        //     $model->save(['member_id' => '0', 'title' => $data->title, 'content' => $data->content, 'create_time' => date('Y-m-d H:i:s',time())]);
        // });

    }

}